package com.bjpowernode.boss.mvc.controller;

import com.bjpowernode.boss.mvc.models.dto.LoginResultDto;
import com.bjpowernode.boss.mvc.models.dto.MenusDto;
import com.bjpowernode.boss.mvc.models.query.LoginQuery;
import com.bjpowernode.boss.mvc.models.response.AjaxResult;
import com.bjpowernode.boss.mvc.service.OperatorService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class OperatorController {

    @Resource
    private OperatorService operatorService;

    @PostMapping("/operator/access")
    public AjaxResult login(@RequestBody @Valid LoginQuery loginQuery) {

        LoginResultDto loginResultDto = operatorService.login(loginQuery);

        return AjaxResult.OK(loginResultDto);

    }

    @GetMapping("/operator/menus")
    public AjaxResult getMenus(@RequestHeader("operatorId") Integer operatorId) {
        List<MenusDto> menus = operatorService.getMenus(operatorId);


        return AjaxResult.OK(menus);
    }

    @GetMapping("/operator/logout")
    public AjaxResult logout(@RequestHeader Integer operatorId) {
        operatorService.logout(operatorId);
        return AjaxResult.OK();
    }

}
